package 滑动;

public class _1052爱生气的书店老板 {
    /**
     * 
     * @param customers customers[i] 是在第 i 分钟开始时进入商店的顾客数量
     * @param grumpy    1代表生气
     * @param minutes   技能：压制怒气
     * @return  最多有多少客户能够感到满意
     * 
        n == customers.length == grumpy.length
        1 <= minutes <= n <= 2 * 104
        0 <= customers[i] <= 1000
        grumpy[i] == 0 or 1
     * 
     * 
     */
    public static int maxSatisfied(int[] customers, int[] grumpy, int minutes) {
        int n = customers.length;
        int basic = 0;
        for (int i = 0; i < n; i++) {
            int mood = grumpy[i];
            if (mood == 0) {
                basic += customers[i];
            }
        }
        int res = 0;
        int sum = 0;
        //win
        for (int i = 0; i < n; i++) {
            int mood = grumpy[i];
            if (mood == 1) {//生气了到窗口变成好的可以加
                sum += customers[i];
            }
            if (i < minutes - 1) {
                continue;
            }
            res = Math.max(res, sum);
            int start = i - minutes + 1;
            if (grumpy[start] == 1) {//窗口结束，因为生气被加到额外的要去掉了
                sum -= customers[start];
            }
        }
        return basic + res;
    }

    public static void main(String[] args) {
        int maxSatisfied = maxSatisfied(new int[]{1,0,1,2,1,1,7,5}, new int[]{0,1,0,1,0,1,0,1}, 3);
        System.out.println("=========="+maxSatisfied);
    }

    
}
